package ext.acae2.dms.send;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentItem;
import wt.content.ContentRoleType;
import wt.content.ContentServerHelper;
import wt.content.Streamed;
import wt.doc.WTDocument;
import wt.enterprise.RevisionControlled;
import wt.epm.EPMDocument;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.ReferenceFactory;
import wt.fc.WTReference;
import wt.fc.collections.WTSet;
import wt.log4j.LogR;
import wt.part.Quantity;
import wt.part.WTPart;
import wt.part.WTPartConfigSpec;
import wt.part.WTPartHelper;
import wt.part.WTPartStandardConfigSpec;
import wt.part.WTPartUsageLink;
import wt.pds.oracle81.OracleDataSource;
import wt.session.SessionServerHelper;
import wt.util.WTException;
import wt.util.WTMessage;
import wt.util.WTProperties;
import wt.vc.views.ViewHelper;

import com.ptc.windchill.wp.WPHelper;
import com.ptc.windchill.wp.WorkPackage;

import ext.acae2.dms.bean.DocReferenceLinkBean;
import ext.acae2.dms.bean.DocumentBean;
import ext.acae2.dms.bean.EPMDocumentBean;
import ext.acae2.dms.bean.PartBean;
import ext.acae2.dms.bean.PartUsageLinkBean;
import ext.acae2.dms.load.DocumentFactory;
import ext.acae2.dms.resource.DataExchangeResource;
import ext.acae2.dms.web.input.WebConstants;
import ext.acae2.dms.web.output.DownloadFileProcessor;
import ext.acae2.dms.web.output.DownloadProcessor;
import ext.acae2.dms.web.output.TozipProcessor;
import ext.acae2.part.PartHelper;
import ext.acae2.util.FileUtil;
import ext.acae2.util.ParameterUtil;
import ext.acae2.util.ParseDepartmentConfig;

public class DataSendHelper {
	private static String dataSendDeptXml;
	public static Map<String, String> sendDeptMap;
	public static Map<String, String> deptCodeMap;
	static {
		try {
			String codebasePath = WTProperties.getLocalProperties()
					.getProperty("wt.codebase.location");
			dataSendDeptXml = codebasePath + File.separator + "ext"
					+ File.separator + "acae2" + File.separator + "dms"
					+ File.separator + "sendDepartmentConfig";
			sendDeptMap = ParseDepartmentConfig.execute(dataSendDeptXml
					+ File.separator + "sendDeptData.xml");
			deptCodeMap = ParseDepartmentConfig.execute(dataSendDeptXml
					+ File.separator + "deptCode.xml",
					"//DepartmentConfig/Department", "name", "deptCode");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private static final Logger LOGGER = LogR.getLogger(DataSendHelper.class
			.getName());

	private static final String RESOURCE = DataExchangeResource.class.getName();

	public static final String HTML_DATA_SEND_LINK = "<a href=\"netmarkets/jsp/ext/acae2/dms/downloadSendData.jsp?oid=";
	public static final String HTML_LINK_BLANK_MID = "\" target=\"_blank\">";
	public static final String HTML_LINK_AFTER = "</a>";
	public static final String SPILT_CODE = "-";

	/**
	 * @author cnie
	 * @return
	 * @throws Exception
	 */
	public static String getSendDeptLink() throws Exception {
		String selAllDept = WTMessage.getLocalizedMessage(RESOURCE,
				DataExchangeResource.SELECT_ALLL_DEPARTMENT);
		StringBuffer link = new StringBuffer();

		link.append(
				"<table><tr><td><input type=\"checkbox\" onclick=\"selectALLDept(this)\">")
				.append(selAllDept).append("</input><td></tr>");
		Set<String> keys = sendDeptMap.keySet();
		java.util.Iterator<String> it = keys.iterator();
		while (it.hasNext()) {
			String name = it.next();
			String displayvalue = sendDeptMap.get(name);
			link.append(
					"<tr><td><input type=\"checkbox\" onclick=\"selectDepartment(this)\" name=\"sendDept\" value=\"")
					.append(name).append("\">").append(displayvalue)
					.append("</input></td></tr>");
		}
		link.append("</table>");
		return link.toString();

	}

	/**
	 * @author cnie
	 * @param selDepartment
	 * @return
	 */
	public static String displaySendDept(String selDepartment) {
		StringBuffer deptDisplayValue = new StringBuffer();
		String[] selDepartmentArr = selDepartment.split(",");
		Set<String> keys = sendDeptMap.keySet();
		for (String selDept : selDepartmentArr) {
			if (keys.contains(selDept)) {
				String displayvalue = sendDeptMap.get(selDept);
				deptDisplayValue.append(displayvalue);
			} else {
				deptDisplayValue.append(selDept);
			}
			if (!selDept.equals(selDepartmentArr[selDepartmentArr.length - 1])) {
				deptDisplayValue.append("<br/>");
			}
		}
		return deptDisplayValue.toString();
	}

	/**
	 * 构造下载Link
	 * 
	 * @author cnie
	 * @param wp
	 * @return
	 */
	public static String getSendDataDowloadLink(String docOids) {
		String[] docOidArr = docOids.split("#");

		StringBuffer links = new StringBuffer();
		for (String docOidSupplier : docOidArr) {

			String[] docOidsupplierArr = docOidSupplier.split(",");
			Set<String> keys = sendDeptMap.keySet();
			String supplierFullName = docOidsupplierArr[1];
			if (keys.contains(docOidsupplierArr[1])) {
				supplierFullName = sendDeptMap.get(docOidsupplierArr[1]);
			}
			String link = HTML_DATA_SEND_LINK + docOidsupplierArr[0]
					+ HTML_LINK_BLANK_MID + "点击下载发放到" + supplierFullName + "文件"
					+ HTML_LINK_AFTER;
			links.append(link);
			links.append("<br/>");
		}
		// String wpOid = PersistenceHelper.getObjectIdentifier(wp).toString();

		return links.toString();
	}

	/**
	 * 获取包中的下载文件
	 * 
	 * @param objOid
	 *            包对应的OID
	 * @param response
	 * @return 文件名称
	 * @throws Exception
	 */
	public static void downloadFile(String objOid, HttpServletResponse response)
			throws Exception {
		boolean force = SessionServerHelper.manager.setAccessEnforced(false);
		OutputStream os = response.getOutputStream();
		ReferenceFactory rf = new ReferenceFactory();
		Persistable p = rf.getReference(objOid).getObject();
		if (p instanceof WTDocument) {
			WTDocument doc = (WTDocument) p;
			QueryResult qr = ContentHelper.service.getContentsByRole(doc,
					ContentRoleType.PRIMARY);
			while (qr.hasMoreElements()) {
				ContentItem contentitem = (ContentItem) qr.nextElement();
				ApplicationData applicationdata = (ApplicationData) contentitem;
				String fileName = applicationdata.getFileName();
				if (fileName.endsWith(".zip") || fileName.endsWith(".rar")) {
					Streamed streamed = (Streamed) applicationdata
							.getStreamData().getObject();
					InputStream is = streamed.retrieveStream();
					// fileName = fileName.substring(fileName.indexOf("-")+1);
					fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
					response.setContentType("application/x-msdownload; charset=UTF-8");
					response.setHeader("Content-Disposition",
							"attachment; filename=\"" + fileName + "\"");
					byte[] buf = new byte[1024];
					int len = 0;
					while ((len = is.read(buf)) != -1) {
						os.write(buf, 0, len);
					}
					os.flush();
					os.close();
					if (is != null)
						is.close();
					response.setStatus(HttpServletResponse.SC_OK);
					response.flushBuffer();
					os.flush();
					break;
				}
			}
		}
		SessionServerHelper.manager.setAccessEnforced(force);
	}

	/**
	 * 获取包中已包含的对象
	 * 
	 * @param obj
	 * @param resultList
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("rawtypes")
	public static List getWPContinarItem(Object obj) throws Exception {

		List<WTPart> parts = new ArrayList<WTPart>();
		if (obj instanceof WorkPackage) {
			WorkPackage wp = (WorkPackage) obj;
			WTSet objs = WPHelper.service.getAllSeeds(wp);
			System.out.println(objs.size());
			LOGGER.debug("wp size=======>" + objs.size());
			for (java.util.Iterator it = objs.iterator(); it.hasNext();) {
				Persistable p = ((WTReference) it.next()).getObject();
				if (p instanceof WTPart) {
					WTPart part = (WTPart) p;
					parts.add(part);
				}
			}
		}
		return parts;
	}

	/**
	 * 得到零部件的完整的Bom结构
	 * 
	 * @param root
	 * @param configSpec
	 * @param resultList
	 * @throws WTException
	 */
	public static void getBOMDataMembers(WTPart root,
			WTPartConfigSpec configSpec, Map<String, List> resultMap,
			String fileName, String supplier) throws Exception {
		PartBean parentPartBean = constructXMLMAp(root, fileName, resultMap,
				supplier);
		QueryResult childPartsQs = WTPartHelper.service.getUsesWTParts(root,
				configSpec);
		while (childPartsQs.hasMoreElements()) {
			Object obj[] = null;
			obj = (Object[]) childPartsQs.nextElement();
			if (obj[1] instanceof WTPart) {
				WTPart childPart = (WTPart) obj[1];
				WTPartUsageLink alink = (WTPartUsageLink) obj[0];
				Quantity quantity = alink.getQuantity();
				// System.out.println("=======parent======"+root.getName()+"=========child========"+childPart.getName());
				PartBean childPartBean = constructXMLMAp(childPart, fileName,
						resultMap, supplier);
				PartUsageLinkBean partUsageLinkBean = DataSendBeanConstruct
						.constructPartUsageLinkBean(parentPartBean,
								childPartBean, quantity);
				checkDataBeanExitAndPut(ParameterUtil.PARTUSAGELINKBEAN,
						partUsageLinkBean, resultMap);
				getBOMDataMembers(childPart, configSpec, resultMap, fileName,
						supplier);
			}
		}
	}

	/**
	 * 构建xml文件的Map数据(除part与part之间的关系构造)
	 * 
	 * @param part
	 * @param fileName
	 * @param resultMap
	 * @param dataList
	 * @throws Exception
	 */
	public static PartBean constructXMLMAp(WTPart part, String fileName,
			Map<String, List> resultMap, String supplier) throws Exception {
		PartBean rootBean = DataSendBeanConstruct.constructPartBean(part,
				fileName, supplier);
		List<RevisionControlled> rcs = PartHelper.getPartReleatedDOC(part);
		List<EPMDocumentBean> epmBeans = new ArrayList<EPMDocumentBean>();
		for (RevisionControlled rc : rcs) {
			if (rc instanceof WTDocument) {
				WTDocument doc = (WTDocument) rc;
				List<DocumentBean> docBeanList = DataSendBeanConstruct
						.constructDocumentBean(doc, fileName, supplier);
				
				for (DocumentBean docBean : docBeanList) {
					checkDataBeanExitAndPut(ParameterUtil.DOCUMENTBEAN, docBean,
							resultMap);
					DocReferenceLinkBean docLinkBean = DataSendBeanConstruct
							.constructDocRefLinkBean(rootBean, docBean);
					checkDataBeanExitAndPut(ParameterUtil.DOCREFERENCELINKBEAN,
							docLinkBean, resultMap);
				}
				
			} else if (rc instanceof EPMDocument) {
				EPMDocument epm = (EPMDocument) rc;
				Map map = DataSendBeanConstruct
						.constructEPMDocumentBean(epm, fileName, supplier);
				epmBeans.add((EPMDocumentBean)map.get("epm"));
				
				if((DocumentBean)map.get("doc") != null){
					checkDataBeanExitAndPut(ParameterUtil.DOCUMENTBEAN, (DocumentBean)map.get("doc"),
							resultMap);
					DocReferenceLinkBean docLinkBean = DataSendBeanConstruct
							.constructDocRefLinkBean(rootBean, (DocumentBean)map.get("doc"));
					checkDataBeanExitAndPut(ParameterUtil.DOCREFERENCELINKBEAN,
							docLinkBean, resultMap);
				}
				
			}
		}
		rootBean.setEpmDocList(epmBeans);
		// System.out.println("=============>"+rootBean.getName()+":::::"+rootBean.getNumber()+":::"+rootBean.getEpmDocList().size());
		checkDataBeanExitAndPut(ParameterUtil.PARTBEAN, rootBean, resultMap);
		return rootBean;
	}

	/**
	 * 将Bean放入Map中
	 * 
	 * @param type
	 * @param objBean
	 * @param resultMap
	 */
	@SuppressWarnings("rawtypes")
	public static void checkDataBeanExitAndPut(String type, Object objBean,
			Map<String, List> resultMap) {
		List objBeans = resultMap.get(type);
		if (objBeans == null || objBeans.size() == 0) {
			objBeans = new ArrayList();
			objBeans.add(objBean);
			resultMap.put(type, objBeans);
		} else {
			if (type.equals(ParameterUtil.PARTBEAN)) {
				for (PartBean partBean : (List<PartBean>) objBeans) {
				}
			}
			if (!objBeans.contains(objBean)) {
				objBeans.add(objBean);
			}
		}
	}

	/**
	 * 获取流水号
	 * 
	 * @author cnie
	 * @param send_data
	 * @return
	 */
	public static String getSendDataSEQ(String send_dept, String send_data) {
		Connection conn = null;
		ResultSet resultset = null;
		PreparedStatement ps = null;
		String liushuiNum = "";
		String insertSql = "";
		// String newliushuiNum="";
		try {
			String sql = "select max(seq_number) from ACAE_DATA_SEND_NUMBER where send_data=? and send_dept=?";
			conn = OracleDataSource.getOracleDataSource().getConnection();
			ps = conn.prepareStatement(sql);
			ps.setString(1, send_data);
			ps.setString(2, send_dept);
			resultset = ps.executeQuery();
			if (resultset.next()) {
				liushuiNum = resultset.getString(1);
			}
			if (StringUtils.isBlank(liushuiNum)) {
				insertSql = "insert into ACAE_DATA_SEND_NUMBER values(ACAE_DATA_SEND_NUMBER_SEQ.Nextval,?,?,'01')";
			} else {
				if (liushuiNum.startsWith("0") && !liushuiNum.endsWith("9")) {
					liushuiNum = "0"
							+ String.valueOf(Integer.parseInt(liushuiNum) + 1);
				} else {
					liushuiNum = String
							.valueOf(Integer.parseInt(liushuiNum) + 1);
				}
				insertSql = "insert into ACAE_DATA_SEND_NUMBER values(ACAE_DATA_SEND_NUMBER_SEQ.Nextval,?,?,?)";
			}
			// conn = OracleDataSource.getOracleDataSource().getConnection();
			conn.setAutoCommit(false);
			ps = conn.prepareStatement(insertSql);
			ps.setString(1, send_dept);
			ps.setString(2, send_data);
			if (StringUtils.isNotBlank(liushuiNum)) {
				ps.setString(3, liushuiNum);
			}
			ps.executeUpdate();
			conn.commit();

		} catch (Exception e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} finally {
			close(conn, ps, resultset);
		}
		return StringUtils.isBlank(liushuiNum) ? "01" : liushuiNum;
	}

	public static void close(Connection conn, PreparedStatement ps,
			ResultSet resultset) {
		try {
			if (resultset != null) {
				resultset.close();
			}
			if (ps != null) {
				ps.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 得到文件夹的名称命名规则
	 * 
	 * @param parts
	 * @param wp
	 * @return
	 */
	public static String getFileName(List<WTPart> parts, WorkPackage wp) {
		String fileName = null;
		if (parts.size() == 1) {
			String name = parts.get(0).getName();
			String number = parts.get(0).getNumber();
			String version = parts.get(0).getVersionIdentifier().getValue();
			String iteration = parts.get(0).getIterationIdentifier().getValue();
			fileName = number;
			//fileName = number + "_" + version + "_" + iteration + "_" + name;
		} else {
			String wpName = wp.getName();
			String wpNumber = wp.getNumber();
			// String wpversion = wp.getVersionIdentifier().getValue();
			// String wpiteration = wp.getIterationIdentifier().getValue();
			fileName = wpNumber + "_" + wpName;
		}
		return fileName;
	}

	/**
	 * 产生xml文件的模型数据并打成zip数据接口
	 * 
	 * @param pbo
	 * @return
	 * @throws Exception
	 */
	public static String genXmlAndToZip(Object pbo, String deptcode)
			throws Exception {

		String[] deptcodes = deptcode.split("<br/>");
		Set<String> keys = sendDeptMap.keySet();
		String supplier = null;

		DownloadProcessor dp = new DownloadProcessor();
		StringBuffer docoids = new StringBuffer();

		for (int i = 0; i < deptcodes.length; i++) {
			for (java.util.Iterator<String> it = keys.iterator(); it.hasNext();) {
				String key = it.next();
				if (deptcodes[i].equals(sendDeptMap.get(key))) {
					supplier = key;
				}
			}
			LOGGER.debug("supplier==============>"+supplier);

			WTPartStandardConfigSpec standardConfigSpec = WTPartStandardConfigSpec
					.newWTPartStandardConfigSpec(
							ViewHelper.service.getView("Design"), null);
			WTPartConfigSpec configSpec = WTPartConfigSpec
					.newWTPartConfigSpec(standardConfigSpec);
			configSpec.setStandardActive(true);
			Map<String, List> resultMap = new HashMap<String, List>();
			List<WTPart> parts = getWPContinarItem(pbo);
			String fileName = getFileName(parts, (WorkPackage) pbo);
			System.out.println("fileName===========>" + fileName);

			File dataFolder = new File(
					DataSendBeanConstruct.exportFile.getAbsolutePath()
							+ File.separator + supplier + File.separator
							+ fileName);
			FileUtil.deleteDir(dataFolder);
			File secondDataFile = new File(dataFolder.getAbsolutePath()
					+ File.separator + fileName);
			if (!secondDataFile.exists()) {
				secondDataFile.mkdirs();
			}

			for (WTPart part : parts) {
				getBOMDataMembers(part, configSpec, resultMap, fileName,
						supplier);
			}

			String dataType = "F";
			List<PartBean> partBeans = resultMap.get(ParameterUtil.PARTBEAN);
			for (PartBean partBean : partBeans) {
				List<EPMDocumentBean> epmDocBeans = partBean.getEpmDocList();
				if (epmDocBeans != null && epmDocBeans.size() > 0) {
					dataType = "M";
					break;
				}
			}

			File zipFile = dp.process(resultMap, supplier + File.separator
					+ fileName);
			CreateSendDataDocment(pbo, zipFile, supplier, docoids, dataType);
			
			new TozipProcessor().delzip(new DownloadFileProcessor().getDownloadPath(),
					supplier + File.separator+fileName);
			
		}

		return docoids.toString().substring(0, docoids.length() - 1);
		// System.out.println("====>"+fileName);

		// System.out.println(zipFile.getAbsolutePath());
		// return new Object[]{dataType,zipFile};

	}

	/**
	 * @author cnie
	 * @param pbo
	 * @param objArr
	 * @param supplier
	 * @return
	 * @throws Exception
	 */
	public static void CreateSendDataDocment(Object pbo, File zipFile,
			String supplier, StringBuffer docoids, String dataType)
			throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String productCode = "";
		if (pbo instanceof WorkPackage) {
			WorkPackage wp = (WorkPackage) pbo;
			productCode = wp.getContainerName();
		}
		String libName = WTMessage.getLocalizedMessage(RESOURCE, DataExchangeResource.LIB_NAME);
		// String[] supplierArr = supplier.split("<br/>");
		File primaryFile = zipFile;
		// StringBuffer docoids = new StringBuffer();

		// for(String supplierStr:supplierArr){
		// Set<String> keys = sendDeptMap.keySet();
		// java.util.Iterator<String> it = keys.iterator();
		String selectDept = supplier;
		// while(it.hasNext()){
		// String deptname = it.next();
		// String desplayvalue = sendDeptMap.get(deptname);
		// if(desplayvalue.equals(supplierStr)){
		// selectDept = supplier;
		// break;
		// }
		// }
		String sendData = sdf.format(System.currentTimeMillis());
		String liushuiNum = getSendDataSEQ(selectDept, sendData);
		String supplierCode = deptCodeMap.get(selectDept);
		// String zujianNumber =
		// primaryFile.getName().substring(0,primaryFile.getName().indexOf("_"));
//		SimpleDateFormat sd = new SimpleDateFormat("HHmmss");
//		String ly_time = sd.format(new java.util.Date());
		String format = primaryFile.getName().substring(
				primaryFile.getName().lastIndexOf("."));
		String fileName = productCode + SPILT_CODE + "131883" + SPILT_CODE
				+ supplierCode + SPILT_CODE + dataType + SPILT_CODE + sendData
				+ SPILT_CODE + liushuiNum+ format;
		String folder = "/Default/"
				+ WTMessage.getLocalizedMessage(RESOURCE, "FOLDER_NAME_"
						+ selectDept)
				+ "/"
				+ WTMessage.getLocalizedMessage(RESOURCE,
						DataExchangeResource.ROOT_FOLDER_NAME)
				+ "/"
				+ WTMessage.getLocalizedMessage(RESOURCE,
						DataExchangeResource.EXPORT_FOLDER_NAME);
		WTDocument doc = DocumentFactory.getInstance()
				.createCommonDocumentToFolder(WebConstants.DATA_SEND_PACK_TYPE,
						fileName, libName, folder);
		ApplicationData appData = ApplicationData.newApplicationData(doc);
		// appData.setFileName(supplierStr + "-" + primaryFile.getName());
		appData.setFileName(fileName);
		appData.setRole(ContentRoleType.PRIMARY);
		FileInputStream fis = new FileInputStream(primaryFile);
		ContentServerHelper.service.updateContent(doc, appData, fis);
		ContentServerHelper.service.updateHolderFormat(doc);
		String docoid = PersistenceHelper.getObjectIdentifier(doc).toString();
		docoids.append(docoid);
		docoids.append(",");
		docoids.append(selectDept);
		docoids.append("#");
		// if(!supplierStr.equalsIgnoreCase(supplierArr[supplierArr.length-1])){
		// docoids.append("#");
		// }
		LOGGER.debug("====CreateSendDataDocment========docoid==========>"
				+ docoid);
		// }
		// return docoids.toString();
	}

	public static void main(String[] args) throws Exception {

		// RemoteMethodServer rms = RemoteMethodServer.getDefault();
		// GatewayAuthenticator auth = new GatewayAuthenticator();
		// auth.setRemoteUser("wcadmin");
		// rms.setAuthenticator(auth);
		// if (!RemoteMethodServer.ServerFlag) {
		// rms.setUserName("wcadmin");
		// rms.setPassword("wcadmin");
		// rms.invoke("main", DataSendHelper.class.getName(), null,
		// new Class[] { String[].class }, new Object[] { args });
		// }

		// Map<String, List> resultMap = new HashMap<String, List>();
		// WorkPackage wp = (WorkPackage) CSCUtil
		// .getObjectByOid("VR:com.ptc.windchill.wp.WorkPackage:179700");
		// File zipPath = genXmlAndToZip(wp);
		// System.out.println(zipPath.getName());
		// WTDocument doc = (WTDocument)
		// CSCUtil.getObjectByOid("VR:wt.doc.WTDocument:183835");
		// DepartmentList deptList = doc.getDepartment();
		// System.out.println(deptList);
		// String number = getSendDataSEQ("131410","20130226");
		// System.out.println(number);
		Map<String, String> deptCodeMap = ParseDepartmentConfig.execute(
				dataSendDeptXml + File.separator + "deptCode.xml",
				"//DepartmentConfig/Department", "name", "deptCode");
		System.out.println(deptCodeMap.size());
	}

}
